<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司信息</title>
<%@ include file="../common/common.jsp"%>

</head>
<script type="text/javascript">
//新增公司
function newCp_info(){
	$('#dlg').dialog('open').dialog('setTitle', '新增公司');
	$('#fm').form('clear');
}
//编辑公司信息
function editCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dlg').dialog('open').dialog('setTitle', '编辑公司');
		$('#fm').form('load', row);
	}
}

//保存公司信息
function saveCp_info() {
	$('#fm').form('submit', {
		url : '<%=basePath %>saveCompanyAction!saveData.do',
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			//alert(result);
			if (result.message=='success') {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
		} else {
		$.messager.show( {
			title : '错误提示',
			msg : result.message
		});
	}
}
	});
}

function removeCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'请确认是否删除该公司信息?', function(r) {
					if (r) {
						$.post('<%=basePath %>saveCompanyAction!destoryData.do', {
							id : row.id
						}, function(result) {
							if (result.message=='success') {
								$('#dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show( { // show error message
										title : '错误提示',
										msg : result.message
										});
							}
						}, 'json');
					}
				});
	}
}



$(function(){
	
	//布局
	$('#pp').portal({
		border:false,
		fit:true
	});
	
	//组织树
	$('#tt').tree({
		url:"<%=basePath%>getJsonAction!getCompanyListTree.do",
		onClick:function(node){
			//$('#tt').tree('beginEdit', node.target);
			//alert(node.id);
			var companyCode = node.id;
		//	alert(companyCode);
			
			<%-- var url = "<%=basePath%>loadUserInfoAction!loadData.do?"+
			"userinfo.companyCode="+companyCode;
			
			if(companyCode=='000'){
				url = "<%=basePath%>loadUserInfoAction!loadData.do"
			}
		
			var params = {} ;
			jQuery.post(url,params,function(data){
				$('#dg').datagrid("loadData",data);
			
			},'json'); --%>
					
			
		}
	});

	
	
})
</script>
<body>
			
		
<div region="center" border="false">
   <div id="pp" style="position:relative">
	<div style="width:20%;">
	
			<div title="公司信息" collapsible="true" closable="true" style="height:390px;padding:5px;">
			     <ul id="tt" animate="true"></ul>
			</div>
		  
	</div>
	<div style="width:80%;">
	
		<table id="dg" title="公司信息" class="easyui-datagrid"
			style="width: 1000px; height: 370px" url="<%=basePath %>loadCompanyAction!loadData.do"
			toolbar="#toolbar" pagination="true" rownumbers="true"
			fitColumns="true" singleSelect="true" >
			<thead>
				<tr>
					<th field="companyCode" width="20">
						公司代码
					</th>
					<th field="companyName" width="30">
						公司名称
					</th>
				</tr>
			</thead>
		</table>
		
		
		<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
				onclick="newCp_info()">新建</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
				plain="true" onclick="editCp_info()">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
				plain="true" onclick="removeCp_info()">删除</a>
		</div>
		
		<div id="dlg" class="easyui-dialog"
			style="width: 620px; height: 180px; padding: 10px 20px" closed="true"
			buttons="#dlg-buttons">
			
			<form id="fm" method="post" >
			
				<table style="border:1px solid #b3dfda;width:550px" align="center">
				
					<tr  style="display: none">
						
						<td>
							<div class="fitem">
								<label>
									ID:
								</label>
								<input name="id" class="easyui-validatebox" >
							</div>
						</td>
						
					</tr>
					
					<tr>
						
						<td >
							<div class="fitem">
								<label>
									公司代码:
								</label>
								<input name="companyCode" class="easyui-validatebox" required="true">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									公司名称:
								</label>
								<input name="companyName" class="easyui-validatebox" required="true">
							</div>
						</td>

					</tr>

				</table>

			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
				onclick="saveCp_info()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
				onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
		
		
	
	</div>


	</div>
</div>
		
		
		
</body>
</html>